#!/usr/bin/env python3
# -*- coding:UTF-8 -*-
"""
python的类属性、类方法和实例属性、实例方法
类似于JavaScript方式，类属性和类方法就在prototype上面(当然python没有原型概念，挂在类上面)

see:http://www.binarydance.top/aticle_view.html?aticle_id=495415157879746560&t=1624261166678
"""


class TestClass(object):
    # 类属性
    val1 = 'name class'
    val2 = []

    def __init__(self):
        # 实例属性
        self._name = 'name instance - init'
        self._addr = [8]


if __name__ == '__main__':
    inst = TestClass()
    inst1 = TestClass()


    #类上面的val2
    print(TestClass.val2)
    print(inst.val2)
    print(inst1.val2)


    print('=======================')

    #类上面的val2
    TestClass.val2.append(1)
    print(TestClass.val2)
    print(inst.val2)
    print(inst1.val2)

    #类上面的val2
    inst.val2.append(2)
    print(TestClass.val2)
    print(inst.val2)
    print(inst1.val2)

    print('=======================')

    #实例上面创建val2数组
    inst.val2 = [100]
    print(TestClass.val2)
    print(inst.val2)
    print(inst1.val2)

